# 第 0019 题： 将 第 0016 题中的 numbers.xls 文件中的内容写到 numbers.xml 文件中，如下所示：

import xml.etree.ElementTree
from xml.dom import minidom

from openpyxl import load_workbook


def number_excel(xlsx):
    wb = load_workbook(xlsx)
    ws = wb['number']

    number_list = []
    for i, r in enumerate(ws.rows):
        number_list.append([x.value for x in r])
    return str(number_list)


def number_xml(filepath, data):
    doc = xml.dom.minidom.Document()
    root = doc.createElement('root')
    doc.appendChild(root)
    numbers = doc.createElement('numbers')
    numbers.appendChild(doc.createComment('城市信息'))
    numbers.appendChild(doc.createTextNode(data))
    root.appendChild(numbers)
    file = open(filepath, 'w', encoding="utf-8")
    doc.writexml(file, indent='\t', addindent='\t', newl='\n', encoding="utf-8")


if __name__ == '__main__':
    data = number_excel(r'resource/xml/number.xlsx')
    print(data)
    number_xml(r'resource/xml/number.xml', data)
